def sum_three_nums(nums,target):#找出三个数和为目标数并返回下标列表
    num_dict = {}
    num_list = []

    #填充num_dict字典
    for i,num in enumerate(nums):
        if num not in num_dict:
            num_dict[num] = []
        num_dict[num].append(i)

    #遍历每一对元素
    for i in range (len(nums)):
        for j in range(i+1,len(nums)):
            comp = target-nums[i]-nums[j]
            if comp in num_dict:
                #检查是否存在不同的下标
                for k in num_dict[comp]:
                    if k != i and k != j:
                        num_list.append([i,j,k])
    return num_list

#示例
nums = [1,2,4,4,5,6,4,7,5,8]
target = 10
result_list = sum_three_nums(nums,target)
new_dict = {}
for i in range(len(result_list)):
    #出除重复的下标组合
    new_dict[sum(result_list[i])] = result_list[i]
for i in new_dict:
    print("三个数的下标为：",end='')
    print(new_dict[i],end=' ')
    print("对应的三个数为", end=' ')
    for j in new_dict[i]:
        print(nums[j],end=' ')
    print()